package chapter12;

import chapter9.DynamicArray;

import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/20 10:57
 */
public class MyCollection<E> extends AbstractCollection<E> {
    private DynamicArray<E> dynamicArray;

    public MyCollection() {
        this.dynamicArray = new DynamicArray<>();
    }

    public MyCollection(Collection<? extends E> collection) {
        this();
        addAll(collection);
    }

    @Override
    public Iterator<E> iterator() {
        return dynamicArray.iterator();
    }

    @Override
    public int size() {
        return dynamicArray.size();
    }

    @Override
    public boolean add(E e) {
        dynamicArray.add(e);
        return true;
    }
}
